// var nums = [1, 3, 5, 6], target = 2
// var nums = [1, 3, 5, 6], target = 7
// var nums = [1, 3, 5, 6], target = 5
var nums = [1, 3, 5, 6], target = 0

var searchInsert = function (nums, target) {
    if (nums[0] > target) {
        return 0
    }
    for (var i = 0; i < nums.length; i++) {
        if (nums[i] === target) {
            return i

        } else if (nums[i] < target && nums[i + 1] > target) {
            return i + 1

        }
    }
    return nums.length
};
console.log(searchInsert(nums, target));
